/* eslint-disable no-self-assign */
import express, { Router } from 'express'
import users from './api/users'
import login from './api/login'
import content from './api/content'
import account from './api/account'
import qr from './api/qrcode'

const app = express()
const router = Router()

// Transform req & res to have the same API as express
// So we can use res.status() & res.json()
router.use((req, res, next) => {
  Object.setPrototypeOf(req, app.request)
  Object.setPrototypeOf(res, app.response)
  req.res = res
  res.req = req
  next()
})

router.get('/get/session/', function (req, res, next) {
  // console.log(req.session.id)
  // res.json(req.session.id)
  // console.log(req.sessionID)
  // res.json(req.sessionID)
  // console.log(req.session.id)
  // res.json(req.session.id)
  if (req.session.authUser) {
    req.session.authUser = req.session.authUser
  }
  // console.log(req.session.authUser)
  res.json(req.session.authUser)
})

// Add USERS Routes
router.use(users)

router.use(login)

router.use(content)
router.use(qr)

router.use('/account', account)

export default router
